package com.xy.tianyu

import android.os.Bundle
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.ContextCompat
import com.blankj.utilcode.util.BarUtils
import com.xy.tianyu.utils.RevealUtils
import com.xy.tianyu.utils.RevealUtils.circularFinishReveal
import com.xy.tianyu.utils.RevealUtils.setReveal

/**
 * @time 2020/9/14 16:59
 * @class 描述:
 */
abstract class BaseActivity :AppCompatActivity(){
    lateinit var mRootView: View
    abstract fun getLayoutId(): Int
    open fun initView() {}
    open fun initData() {}

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        initBefore()
        setContentView(getLayoutId())
        mRootView = (findViewById<ViewGroup>(android.R.id.content)).getChildAt(0)
        initStatusBar()
        initView()
        initData()
        if (showCreateReveal()) {
            setReveal(savedInstanceState)
        }
    }

    fun initStatusBar() {
        BarUtils.setStatusBarLightMode(this,true)
        BarUtils.setStatusBarColor(this, ContextCompat.getColor(this,R.color.colorPrimary))
    }

    open fun initBefore() {

    }

    open fun showCreateReveal(): Boolean = true
    open fun showDestroyReveal(): Boolean = false

    override fun onPause() {
        super.onPause()
        if (showDestroyReveal()) {
            circularFinishReveal(mRootView)
        }
    }

    override fun finish() {
        super.finish()
        if (showDestroyReveal()) {
            overridePendingTransition(R.anim.alpha_in, R.anim.alpha_out)
        } else {
            overridePendingTransition(
                R.anim.animo_alph_open,
                R.anim.animo_alph_close
            )
        }
    }

}